using System;
using System.Diagnostics;

namespace UnityDemo.LoggingUtility
{
    internal class ConsoleLogger : ILogger
    {
        private Stopwatch _watch;

        #region ILogger Members

        public void Info(string message)
        {
            Console.WriteLine(message);
        }

        public void ExceptionMessage(string message)
        {
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine(message);
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void Write(object sender)
        {
            Write(sender.ToString());
        }

        public void Write(string message)
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine(message);
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void Exception(Exception ex)
        {
            ExceptionMessage(ex.Message);
        }

        public void Warn(string message)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(message);
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void StartWatch(string message = "")
        {
            if (!string.IsNullOrEmpty(message))
                Warn(message);

            _watch = new Stopwatch();
            _watch.Start();
            //_task= new Task(() => WatchMessage(message));
            //_task.Start();
        }

        public void PriorityMessage(string messsage)
        {
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine(messsage);
            Console.ForegroundColor = ConsoleColor.White;
        }

        public void StopWatch()
        {
            Warn("Process completed . Process took " + _watch.Elapsed);
        }

        #endregion
    }
}